package com.example;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;


public class ServerClient implements Message{
    public Socket socket;
    public InputStream is;
    public OutputStream os;

    public ServerClient( Socket socket){
        this.socket = socket;
        try {
            is = socket.getInputStream();
            os = socket.getOutputStream();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }

    public void sendMsg(OutputStream os,String msg)throws Exception{

        String m = msg+"\r\n";
        os.write(m.getBytes());
        os.flush();
    }

    public String readMsg(InputStream is) throws Exception {

        byte[] b = new byte[1024];
        is.read(b);
        String s = new String(b);
        return s.trim();
    }
    public void success()throws Exception{
        os.write(LOGIN);
        os.write(SUCCESS);
        os.flush();
    }
    public void error()throws Exception{
        os.write(LOGIN);
        os.write(ERROR);
        os.flush();
    }

}
